package com.prs.crm.service.sale.impl;

import java.io.Serializable;

import com.prs.crm.context.Constrains;
import com.prs.crm.dao.sale.SalesReceivesRegistDao;
import com.prs.crm.domain.fs.Detail;
import com.prs.crm.domain.sale.SalesReceivesRegist;
import com.prs.crm.service.fs.DetailService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.sale.SalesReceivesRegistService;

public class SalesReceivesRegistServiceImpl extends
		BaseServiceImpl<SalesReceivesRegist, SalesReceivesRegistDao> implements
		SalesReceivesRegistService {

	private SalesReceivesRegistService salesReceivesRegistService;

	private DetailService detailService;

	@Override
	public void saveOrfund(SalesReceivesRegist salesReceivesRegist) {
		this.getSalesReceivesRegistService().save(salesReceivesRegist);
		Double sum = this.getDetailService().getBalanceByAccount(
				salesReceivesRegist.getBankAccount());
		Detail detial = new Detail();
		detial.setSalesReceivesRegist(salesReceivesRegist);
		detial.setIncome(salesReceivesRegist.getBillAmount());
		detial.setPay(0.00);
		detial.setBalance(salesReceivesRegist.getBillAmount() + sum);
		detial.setBankAccount(salesReceivesRegist.getBankAccount());
		detial.setItem(Constrains.FS_ITEMS_SALES);

		this.getDetailService().save(detial);
	}

	public SalesReceivesRegistService getSalesReceivesRegistService() {
		return salesReceivesRegistService;
	}

	public void setSalesReceivesRegistService(
			SalesReceivesRegistService salesReceivesRegistService) {
		this.salesReceivesRegistService = salesReceivesRegistService;
	}

	public DetailService getDetailService() {
		return detailService;
	}

	public void setDetailService(DetailService detailService) {
		this.detailService = detailService;
	}

	@Override
	public SalesReceivesRegist getSalesReceivesRegist(Serializable id) {
		
		return this.getDao().getSalesReceivesRegist(id);
	}

}
